package com.example.score.service.oms;

import com.alibaba.fastjson.JSON;
import com.example.score.dto.AjaxResult;
import com.example.score.entity.vo.AcademicLevelResult;
import com.example.score.service.oms.bean.GetStudentByStudentNumberOutPut;
import com.example.score.utils.HttpUtils;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class OmsService {
    @Value("${api.base-oms-url}")
    private String baseOmsUrl;

    public GetStudentByStudentNumberOutPut getStudentByStudentNumber(String studentNumber) {
        String url = baseOmsUrl + "/open/system/getStudentByStudentNumber";
        log.info("oms调用getStudentByStudentNumber: {}", url);
        // 创建请求体
        String response = HttpUtils.sendGet(url, "studentNumber=" + studentNumber);
        AjaxResult ajaxResult = JSON.parseObject(response, AjaxResult.class);
        Integer code = Integer.parseInt(String.valueOf(ajaxResult.get("code")));
        if (code == 500) {
            return null;
        } else {
            String data = String.valueOf(ajaxResult.get("data"));
            GetStudentByStudentNumberOutPut info = JSON.parseObject(data, GetStudentByStudentNumberOutPut.class);
            return info;
        }
    }
}
